package com.yang.bean.beanfactory.registry.impl;

import com.yang.bean.beanfactory.registry.SingletonBeanRegistry;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 注册实例的接口的默认实现类, 可以来获取对象, 就想spring的三级缓存一样
 * @author: Yang Qiang
 * @create: 2021-11-07 17:40
 */
public class DefinitionSingletonBeanRegistry implements SingletonBeanRegistry {

    // bean的缓存
    Map<String, Object> singletons = new HashMap<>();


    /**
     * 获取bean
     * @param name
     * @return
     */
    @Override
    public Object getSingletonBean(String name) {
        return singletons.get(name);
    }

    /**
     * 注册bean
     * @param name
     * @param bean
     */
    @Override
    public void registrySingletonBean(String name, Object bean) {
        singletons.put(name, bean);
    }
}
